{template 'common/header'}
<script>
    function add(){
        var name = $("#name").val();
        if(name != ''){
            $.ajax({
                type : 'post',
                url : "{php echo $this->createWebUrl('goods',array('op' => 'add_unit'))}",
                data : {'name' : name},
                success : function(data){
                    if(data == 111){
                        alert("操作成功！");
                        location.reload();
                    }else{
                        alert(data);
                    }
                }
            });
        }
    }
    $(function(){
        $(".del-unit").click(function(){
            if(confirm("是否确定删除？")){
                var id = $(this).attr("unit_id");
                if(id > 0){
                    var url = "{php echo $this->createWebUrl('goods',array('op' => 'del_unit'))}";
                    $.ajax({
                        type : "post",
                        url : url,
                        data : {'id' : id},
                        success : function(data){
                            if(data == 111){
                                alert("操作成功！");
                                location.reload();
                            }else if(data == 333){
                                alert("该分类不存在！");
                            }else{
                                alert("服务器繁忙，请重试！");
                            }
                        }
                    });
                }

            }
        });
    });
</script>
<ul class="nav nav-tabs">
    <li ><a href="{php echo $this->createWebUrl('goods',array('op'=>'index'));}">商品列表</a></li>
    <li ><a href="{php echo $this->createWebUrl('goods', array('op'=>'add'))}">新增商品</a></li>
    <li class="active" ><a href="{php echo $this->createWebUrl('goods', array('op'=>'unit'))}">单位管理</a></li>
</ul>
<div class="main">
    <div class="row">
            <div class="col-xs-3">
                <input type="text" id="name" class="form-control" placeholder="单位名称"/>
            </div>
        <div class="col-xs-2">
            <button onclick="add();" class="btn btn-primary">添加</button>
        </div>
    </div>
    <br />
    <div>
        <table class="table">
            <tr>
                <th>单位</th>
                <th>操作</th>
            </tr>
            {loop $unit $u}
            <tr>
                <td>
                    {$u['name']}
                </td>
                <td>
                    <button class="btn btn-danger del-unit" unit_id="{$u['id']}">删除</button>
                </td>
            </tr>
            {/loop}
        </table>
    </div>
</div>



{template 'common/footer'}